package mahmoud.sigir.parse;

import java.io.File;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;

import mahmoud.utils.SigirDoc;

public abstract class DocParser 
{
	private String location;
	protected Queue<String> filesToParse;
	DocParser (String RawDataSetLocation)
	{
		location = RawDataSetLocation;
		filesToParse = new LinkedList<String>();
		File dir = new File(location);
		fillQueue(dir);
		
	}
	public void fillQueue(File f)
	{
		if(f.isFile())
		{
			if(!filesToParse.contains(f.getAbsolutePath()))
			{
				filesToParse.add(f.getAbsolutePath());
				System.out.println("File: "+ f.getAbsolutePath() + " Added to queue");
			}
		}
		else if(f.isDirectory())
		{
			for(File x: f.listFiles())
				fillQueue(x);
		}
		
	}
	public boolean hasMoreDocs()
	{
		if(filesToParse.isEmpty())
			return false;
		return true;
	}
	public HashMap<String,SigirDoc> nextDoc()
	{
		if(filesToParse.isEmpty())
			return null;
		return parseFile(filesToParse.poll());
	}
	
	public abstract HashMap<String,SigirDoc> parseFile(String filePath);
//	public abstract boolean open(String DataSetPath);
//	public abstract boolean close();
//	public abstract HashMap<String, String> 
//	public static void main(String[] args)
//	{
//		System.out.println("from Parser");
//		DocParser DP = new DocParser("D:\\dDocuments\\Code\\TREC4\\FT");
//		System.out.println(DP.filesToParse.size()+" files were added");
//		while(DP.hasMoreDocs())
//			DP.nextDoc();
//		System.out.println(DP.filesToParse.size()+" files are left");
//	}

}
